package com.xiaobai.shardingsphere.mapper;

import com.xiaobai.shardingsphere.entity.UserVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
@Mapper
public interface UserMapper {
    /**
     * 新增用户
     */
    @Insert("INSERT INTO users(username,phone,status) VALUE(#{userName},#{phone},#{status})")
    int insertUser(UserVO userVO);

    /**
     * 查询用户
     */
    @Select({
            "<script>" +
                    " select * from users u where u.id in " +
                    "<foreach collection='userIds' item='id' open='(' separator=',' close=')'>#{id}</foreach>" +
                    "</script>"})
    List<Map<String, Object>> selectUserbyIds(@Param("userIds") List<Long> userIds);

    /**
     * 查询
     */
    @Select("select * from users order by username asc")
    List<Map<String, Object>> list();
}
